<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Investor_model extends CI_Model {

	public $tablename = 'hpg_investor';

	public function __construct()
	{
		parent::__construct();
	}
	
	public function getList($id){
	    if( !$id ){
	        return false;
	    }
		$list = $this->db->from($this->tablename)->where('ins_id', $id)->get_array();
		return $list ? $list : [];
	}
	
	public function gePageList($keyword, $page=1, $limit=20){
	    $start = ($page-1)*$limit;
	    $query = $this->db;
	    if( $keyword ){
	        $query->like('instustry_name', $keyword);
	    }
	    $count = $query->count_all_results($this->tablename, false);
	    $list = $query->select('*')->limit($limit, $start)->get_array();
	    return [intval($count), $list ? $list : []];
	}
	
	public function insert_batch($list){
		if( !$list ){
			return false;
		}
		$res = $this->db->insert_batch($this->tablename, $list);
		return $res;
	}
	
	public function insert($data){
		if( !$data ){
			return false;
		}
		$res = $this->db->insert($this->tablename, $data);
		return $this->db->insert_id();
	}
	
	public function update($map, $data){
		if( !$map || !$data ){
			return false;
		}
		$res = $this->db->update($this->tablename, $data, $map);
		return $res;
	}
	
	public function delete($map){
		if( !$map ){
			return false;
		}
		$res = $this->db->delete($this->tablename, $map);
		return $res;
	}
}